<?php

namespace App\Http\Controllers\Backend;

use App\Http\Resources\Backend\BookRuleResource;
use App\Models\BookRule;
use Illuminate\Http\Request;

/**
 *
 * 订餐规则列表
 *
 * Class BookRuleController
 * @package App\Http\Controllers\Backend
 */
class BookRuleController extends BackendController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
     * 订餐规则列表
     */
    public function index(Request $request)
    {
        $bookRules = BookRule::orderBy('created_at', 'desc')
            ->with('prices.category')
            ->with('school')->with('foods')
            ->schoolIs($request->school_id)
            ->eatTypeIs($request->eat_type)
            ->eatDateIs($request->eat_date)
            ->isCancel($request->is_cancel)
            ->isSettled($request->is_settled)
            ->paginate($request->size);
        return BookRuleResource::collection($bookRules);
    }
}
